package me.zhengjie.pojo;

import java.util.HashMap;
import java.util.Map;

/**
 * Description: 统一返回前端格式
 * Author: huang
 * CreateTime: 2021/6/23 上午8:23
 */

public class Resp extends HashMap<String,Object> {

    public static RespBuilder builder(){
        return new RespBuilder();
    }

    public static class RespBuilder{
        private final Map<String,Object> data = new HashMap<>();

        private String msg;

        private int status;

        public RespBuilder data(String k,Object v) {
            this.data.put(k,v);
            return this;
        }

        public RespBuilder msg(String msg) {
            this.msg = msg;
            return this;
        }

        public RespBuilder status(int status) {
            this.status = status;
            return this;
        }

        public Resp build(){
            Resp resp = new Resp();
            resp.put("data",this.data);
            Meta meta = new Meta(this.msg,this.status);
            resp.put("meta",meta);
            return resp;
        }
    }

    public static class Meta{
        private final String msg;
        private final int code;

        public Meta(String msg, int code) {
            this.msg = msg;
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public int getCode() {
            return code;
        }
    }
}
